home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Tutorial / Script2.vu < prev    next >
Encoding:
Text File  |  1998-06-04  |  4.4 KB  |  138 lines  |  [TEXT/MPS ]

  1. # **********************************************************************
  2. # File:                    Script 2.vu
  3. #
  4. # Purpose:                to demonstrate screen independence,
  5. #                        matching, and list usage
  6. #
  7. # Prerequisites:        This script assumes that DrawShapesVU is the
  8. #                        currently active application on the target.
  9. #
  10. # Note:                    If an attempt is made to draw a shape and
  11. #                        the shape does not materialize, it may be
  12. #                        because the shape being drawn is smaller than 
  13. #                        DrawShapeVU's minimum shape size, not because
  14. #                        there is a problem with VU.
  15. #
  16. # Written by:            David Gaxiola
  17. #
  18. # Copyright © 1992 by Apple Computer, Inc., all rights reserved.
  19. #
  20. # **********************************************************************
  21.  
  22. # Variables here are globals; that is, they are used
  23. # throughout the script.  They begin with a lowercase g.
  24.  
  25. # variable definitions:
  26.  
  27. gToolColumn := 18;                        # relative x position
  28.                                         # inside the window
  29.                                         
  30. gToolRow := { 40,80,120,160 };            # relative y positions
  31.                                         # for tools in window
  32.                                         
  33. gWindowMod := { 41, 21, -21, -21 };        # Modify position for
  34.                                         # actual drawing space.
  35.                                         
  36. gWindowDim := { };                        # Declare empty list
  37.                                         # for window dimensions.
  38.                                         
  39. gScreenDim := { };                        # Declare empty list
  40.                                         # for screen dimensions.
  41.  
  42. # Begin main body. ***************************************************
  43.  
  44. MouseSpeed( 10 );
  45.  
  46. # Get main screen dimensions and put them into a list called
  47. # "gScreenDim".
  48. # Note the importance of using ?gScreenDim instead of
  49. # just gScreenDim. The first puts the dimensions into a
  50. # variable called gScreenDim. The second would not produce
  51. # a meaningful result.
  52.  
  53. match [ screen rectangle:?gScreenDim menubar:true ];
  54.  
  55. # Create a new work window and manually size it
  56. # to nearly the screen size.
  57. # Note how the regular expression /Untitled-≈/ is used 
  58. # to make the selection of the title flexible and how the
  59. # ordinal o:1 is used to denote the frontmost window.
  60.  
  61. println "# Setting up new document window.";
  62. select [ menuItem title:'New' menu:[menu title:'File' ]];
  63. Wait(2);
  64. drag [ window title:/Untitled-≈/ o:1 ] a:{ 1, 21 };
  65. size [ window title:/Untitled-≈/ o:1 ] width:( gScreenDim[3] - 2 ) 
  66.             height:( gScreenDim[4] - 22 );
  67.  
  68. # Determine and record the size of the top work window.
  69.  
  70. match [ window rectangle:?gWindowDim ordinality:1 ];
  71.  
  72. # Draw a square with random position and size,
  73. # yet still within the window bounds.
  74. # Note the use of the built-in task random()
  75. # as well as the use of lists in the equations.
  76.  
  77. println "# Performing square drawing operation.";
  78. move absolute:{ (gWindowDim[1] + gToolColumn), 
  79.                         (gWindowDim[2] + gToolRow[2])};
  80. click;
  81. xStart := Random( (gWindowDim[1] + gWindowMod[1]), 
  82.                         (gWindowDim[3] + gWindowMod[3]) );
  83. xStop := Random( (gWindowDim[1] + gWindowMod[1]), 
  84.                         (gWindowDim[3] + gWindowMod[3]) );
  85. yStart := Random( (gWindowDim[2] + gWindowMod[2]), 
  86.                         (gWindowDim[4] + gWindowMod[4]) );
  87. yStop := Random( (gWindowDim[2] + gWindowMod[2]), 
  88.                         (gWindowDim[4] + gWindowMod[4]) );
  89.  
  90. move absolute:{ xStart, yStart };
  91. pressMouse;
  92. Wait(1);
  93. move absolute:{ xStop, yStop };
  94. releaseMouse;
  95.  
  96. # Alter window size and update the main gWindowDim.
  97. # Note the use of the replace built-in task and of
  98. # list manipulation.
  99.  
  100. println "# Sizing window.";
  101. size [ window title:/Untitled-≈/ ordinality:1 ] rectangle:{ -40, 0 };
  102. match [ window rectangle:?tempDim ordinality:1 ];
  103. gWindowDim := replace( tempDim[3], 3, gWindowDim );
  104.  
  105. ### Draw an oval:
  106.  
  107. println "# Performing oval drawing operation.";
  108. move absolute:{ (gWindowDim[1] + gToolColumn),
  109.                         (gWindowDim[2] + gToolRow[3]) };
  110. click;
  111.  
  112. xStart := Random( (gWindowDim[1] + gWindowMod[1]), 
  113.                         (gWindowDim[3] + gWindowMod[3]) );
  114. xStop := Random( (gWindowDim[1] + gWindowMod[1]), 
  115.                         (gWindowDim[3] + gWindowMod[3]) );
  116. yStart := Random( (gWindowDim[2] + gWindowMod[2]), 
  117.                         (gWindowDim[4] + gWindowMod[4]) );
  118. yStop := Random( (gWindowDim[2] + gWindowMod[2]), 
  119.                         (gWindowDim[4] + gWindowMod[4]) );
  120.  
  121. move absolute:{ xStart, yStart };
  122. pressMouse;
  123. Wait(1);                                 # for slower targets
  124. move absolute:{ xStop, yStop };
  125. releaseMouse;
  126.  
  127. ### Discard the window when finished:
  128.  
  129. println "# Discarding window.";
  130. close [ window title:/Untitled-≈/ ordinality:1 ];
  131. Wait(1);                                 # for slower targets
  132. select [ button title:'No' window:[ window style:dialog ]];
  133.  
  134. println "# Finished";
  135. # End main body. ***************************************************
  136.